export const STORAGE_KEY = 'todos-vuejs'

export const mutations = {

    // 设置loading
    updateLoading (state, loading) {
        state.isLoading = loading
    },

    // 设置MaskLoading
    showMask (state, loading) {
        state.showMask = loading
    },

    // 设置路由切换顺序
    updateDirection (state, payload) {
        state.direction = payload.direction
    },

    // 是否显示底部导航
    updateShowFooter (state, payload) {
    	state.showFooter = payload.showFooter
    },

    // 是否成功获取兴趣点
    updateIsPosition (state, payload) {
    	state.isPosition = payload
    },

    // 更新小店购物车列表
	updateSufreshCarts (state, { products }) {
		state.sufreshCarts = products.data;
        // 更新数量
        if (!products.data){
            return
        }
        let sufreshshops = products.data.shopInfos
			,sufreshCartsNumber=0
		if (sufreshshops && sufreshshops[0] && sufreshshops[0].cmmdtyInfos && sufreshshops[0].cmmdtyInfos.length) {
			sufreshshops.forEach((ov, oi)=>{
				ov.cmmdtyInfos.forEach((tv, ti)=>{
					if(tv.cmmdtyStatus=='1'&&tv.salesType!='2'){
                        sufreshCartsNumber += Number(tv.cmmdtyQty)
                    }
				})
			})
		}
        state.sufreshCartsNumber = sufreshCartsNumber;
	},

	// 更新中心仓购物车列表
	updateCenterCarts (state, { products }) {
		state.centerCarts = products.data
        // 更新数量
        let cmmdtyInfos = products.data.cmmdtyInfos
            ,suningCartsNumber=0;
		if (cmmdtyInfos && cmmdtyInfos.length) {
            cmmdtyInfos.forEach((tv, ti)=>{
                if(tv.mainCmmdtyInfo.mainCmmdtyDetailInfo.cmmdtyStatus == '1'){
                    suningCartsNumber += Number(tv.mainCmmdtyInfo.mainCmmdtyDetailInfo.cmmdtyQty)
                }
            })
		}
        state.centerCartsNumber = suningCartsNumber;
	},


    addTodo (state, { text }) {
        state.todos.push({
            text,
            done: false
        })
    },

    // 首页默认页面
    setDefaultpage (state, payload) {   
        state.home.defaultpage = payload
    },

    updateLoadingStatus (state, payload) {
        state.isLoading = payload.isLoading
    },

    // 设置定位信息
    setPosition(state, position) {
        state.position = position
    },

    // 设置终端信息
    setClient(state, client) {
        state.client = client;
    },
    // 设置用户未保存定位
    setBeforePosition(state,position) {
        state.beforePosition = position
    },
    // 设置citys列表
    setCitysList(state,citys) {
        console.log(citys)
        state.citys = citys
    },
    // 用户当前选择的地址明细
    setDetailAddress(state,detailAddress) {
        state.detailAddress = detailAddress
    },
    AssignDetailAddress(state,detailAddress) {
        state.detailAddress = Object.assign({},state.detailAddress,detailAddress) 
    },
    AssignBeforePosition(state,position) {
        state.beforePosition = Object.assign({},state.beforePosition,position) 
    },
    setDefaultAddress(state, add) {
        state.defaultAddress = add
    },
    setUserInfo(state,info) {
        state.userInfo = info
    },
    setLalPosition(state,p) {
        state.lalPosition = p
    }
}
